
#pragma once
#include "Character_define.h"

#define LEN_MODEL_NAME 5
#define LEN_PATHNAME   256

enum _ModelRCType{RC_MESH = 0,RC_BONE,RC_ANIM,RC_TEXTURE,RC_TEX_NPC,RC_NPCWEAPON,RC_ITEM,RC_TYPEMAX};//order is same with g_ModelRC
enum _ModelRCLinkType{RC_ID_PC = 0,RC_ID_NPCTEXANDANI,RC_ID_NPCSKINANDBONE,RC_ID_NPCWEAPON,RC_ID_ITEM};//order is same with g_RCIDLink

static char _CharTable[]={'M','F','N', 'P'};
static char _PartTable[]={'H','F','C','A','B','M','W','L','X'};
static char _KindTable[]={'B','S','H','C','F','E','P','M','L','X'};

static char _BoneTable[]={'C','F','W','X'};
static char _ItemTable[]={'W','R','A','P','X'};

static char _SpareTable1[] = {'X'};
static char _SpareTable2[] = {'X'};
struct _RCIDLink
{
	_ModelRCLinkType iType;
	char* szLink;
};
struct _ModelRC 
{
	_ModelRCType    iType;
	char*  szDic;
	char*  szExt;
};

static _ModelRC g_ModelRC[] = 
{
	{RC_MESH,        "Mesh","sm"},
	{RC_BONE,        "Bone","bn"},
	{RC_ANIM,        "Animation","an"},
	{RC_TEXTURE,     "Texture","d2s"},
	{RC_TEX_NPC,     "Texture","szt"},
	{RC_NPCWEAPON,   "Mesh","rm"},
	{RC_ITEM,        "ItemModel","rs"},
};

static _RCIDLink g_RCIDLink[] = 
{
	{RC_ID_PC,            "%s%06d"},
	{RC_ID_NPCTEXANDANI,  "%s%04d%02d"},
	{RC_ID_NPCSKINANDBONE,"%s%04d00"},
	{RC_ID_NPCWEAPON,     "NW%cXX%04d00"},
	{RC_ID_ITEM          ,"%c%06d"}
};

class CModelRCName
{	

public:
	CModelRCName()
	{
	}
	virtual ~CModelRCName()
	{
	}
	static CModelRCName& GetSingleton()
	{
		static CModelRCName m_Instance;
		return m_Instance;
	}

	inline const char* GetFullPath(const char* pszName,const _ModelRCType& rcType) 
	{
		sprintf(m_szPathName,"..//datas//%s//%s.%s",g_ModelRC[rcType].szDic,pszName,g_ModelRC[rcType].szExt);
		return m_szPathName;
	}
	//iSub = (RC_ID_ITEM)itemType or (RC_ID_NPCTEXANDANI)iIndexEX
	inline const char* GetFullPath(const _ModelRCDes* pDes,const _ModelRCType& rcType)
	{
		const char* pTmp; 
		if (rcType>=RC_NPCWEAPON)
		{
			pTmp = GetItemRCName(pDes,rcType);
		}
		else
		{
			pTmp = GetModelRCName(pDes,rcType);
		}

		return GetFullPath(pTmp,rcType);
	}

	inline const char* GetModelRCName(const _ModelRCDes* pDes,const _ModelRCType& rcType)
	{
		BOOL bUseIndex;
		const char* szLink = GetModelIDLink(pDes,rcType,bUseIndex);
		const char* szName = GetModelName(pDes,rcType);
		if (szLink)
		{
			if (bUseIndex)
			{
				sprintf(m_szFileName,szLink,szName,pDes->iIndex,pDes->iIndexEX);
			}
			else
			{
				sprintf(m_szFileName,szLink,szName,pDes->iIndex);
			}			
		}		
		else
		{
			sprintf(m_szFileName,"%s",szName);
		}
		return m_szFileName;
	}
	inline const char* GetItemRCName(const _ModelRCDes* pDes,const _ModelRCType& rcType)
	{
		assert(rcType == RC_NPCWEAPON || rcType == RC_ITEM);

		char *pTempType = rcType == RC_NPCWEAPON ? _KindTable : _ItemTable;
		sprintf( m_szFileName ,g_RCIDLink[RC_ID_ITEM].szLink,pTempType[pDes->iClass],pDes->iIndex );

		return m_szFileName;
	}


private:	
	inline const char* GetModelName(const _ModelRCDes* pDes,const _ModelRCType& rcType)
	{
		const int iCharType = (pDes->iNameShare == _NAME_SHARE_NORMAL) ? pDes->iCharType : _MAN;
		const int iClass = ( iCharType!=_NPC && (rcType == RC_MESH || rcType == RC_TEXTURE)&& pDes->iPartType != _ARM) ? _CLASS_MAX : pDes->iClass;
		char* pTmp = (rcType == RC_BONE ) ? _BoneTable : _PartTable;		

		m_cModelName[0] = _CharTable[iCharType];
		m_cModelName[1] = pTmp[pDes->iPartType];
		m_cModelName[2] = _KindTable[iClass];

		m_cModelName[3] = _SpareTable1[0];
		m_cModelName[4] = _SpareTable2[0];

		return m_cModelName;
	}
	inline const char* GetModelIDLink(const _ModelRCDes* pDes,const _ModelRCType& rcType,BOOL& bUseIndexEx) const
	{
		int iIDLink = RC_ID_PC;
		if (pDes->iCharType >= _NPC)
		{
			iIDLink = ( rcType == RC_TEX_NPC || rcType == RC_ANIM) ? RC_ID_NPCTEXANDANI : RC_ID_NPCSKINANDBONE;
		}

		bUseIndexEx = (iIDLink == RC_ID_NPCTEXANDANI ? TRUE : FALSE);
		return g_RCIDLink[iIDLink].szLink;
	}

private:
	char m_szFileName[LEN_PATHNAME];
	char m_szPathName[LEN_PATHNAME];
	char m_cModelName[LEN_MODEL_NAME];
};

